<template>
	<basic-container>
		<avue-crud :option="option" :data="data" :page="page" ref="crud" v-model="form" :before-open="beforeOpen" @row-del="rowDel"
		 @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
		 @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad"></avue-crud>
		<el-dialog title="流程设计" :visible.sync="dialogShow" v-if="dialogShow" top="30px" width="90%" append-to-body>
			<flow-panel :form="form" @closeMoule="closeMoule"></flow-panel>
		</el-dialog>
	</basic-container>
</template>

<script>
	import request from '@/router/axios';
	import FlowPanel from "@/components/ef/panel";
	export default {
		components: {
			FlowPanel
		},
		data() {
			return {
				currentForm: null, // 当前选中的form表单字段信息
				form: {
					frmId: "",
					schemeContent: {}
				},
				dialogShow: false,
				isEdit: false,
				defaultObj: [],
				selectionList: [],
				query: {},
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				option: {
					searchMenuSpan: 4,
					tip: false,
					tree: true,
					border: true,
					index: true,
					viewBtn: false,
					menuWidth: 150,
					dialogWidth: 300,
					dialogHeight: 400,
					column: [{
							label: "流程编号",
							prop: "schemeCode",
							width: "150px"
						},
						{
							label: "流程名称",
							prop: "schemeName",
							search: true,
							width: "250px"
						},
						{
							label: "表单",
							prop: "frmId",
							props: {
								label: "name",
								value: "code"
							},
							dicData: [],
							type: "select",
							width: "150px"
						},
						{
							label: "备注",
							prop: "remark"
						}
					]
				},
				data: []
			};
		},
		computed: {},
		created() {
			request({
				url: '/api/code/getCodes',
				params: {
					typeId: 'CODE200713'
				}
			}).then(res => {
				this.findObject(this.option.column, 'frmId').dicData = res.data.data;
			});
		},
		methods: {
			closeMoule() {
				this.dialogShow = false;
				this.query.frmId = this.form.frmId
				this.onLoad(this.page, this.query);
			},
			beforeOpen(done, type) {
				// if (type=="edit"){
				//   this.isEdit = true;
				//   if (this.$refs.flowSchemeDtl !== undefined) {
				//     this.$refs.flowSchemeDtl.id = this.form.id;
				//   }
				// }
				if (type == "add") {
					//this.isEdit = false;
					this.form = {
						schemeContent: JSON.stringify({
							"nodeList": [],
							"lineList": []
						})
					};
				}
				this.dialogShow = true;
			},
			rowSave(row, loading, done) {
				this.request({
					url: "/api/scheme/add",
					method: "post",
					data: row
				}).then(
					() => {
						loading();
						this.onLoad(this.page);
						done();
					},
					error => {
						done();
						console.log(error);
					}
				);
			},
			rowUpdate(row, index, loading, done) {
				return this.request({
					url: "/api/scheme/edit",
					method: "post",
					data: row
				}).then(
					() => {
						loading();
						this.onLoad(this.page);
					},
					error => {
						done();
						console.log(error);
					}
				);
			},
			rowDel(row) {
				this.$confirm("确定数据删除?", {
						confirmButtonText: "确定",
						cancelButtonText: "取消",
						type: "warning"
					})
					.then(() => {
						return this.request({
							url: "/api/scheme/remove",
							method: "post",
							params: {
								ids: row.id
							}
						});
					})
					.then(() => {
						this.onLoad(this.page);
					});
			},
			searchReset() {
				this.query = {};
				this.page.currentPage = 1;
				this.onLoad(this.page);
			},
			searchChange(params, done) {
				this.page.currentPage = 1;
				this.query = params;
				this.onLoad(this.page);
				done();
			},
			currentChange(currentPage) {
				this.page.currentPage = currentPage;
			},
			sizeChange(pageSize) {
				this.page.pageSize = pageSize;
			},
			onLoad(page) {
				this.request({
					url: "/api/scheme/pages",
					method: "get",
					params: {
						key: this.query.schemeName == undefined ? "" : this.query.schemeName,
						page: page.currentPage,
						limit: page.pageSize
					}
				}).then(res => {
					const data = res.data;
					this.data = data.data;
					this.page.total = data.remark;
				});
			}
		}
	};
</script>

<style>
</style>
